package kfs.light.ui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.WindowConstants;
import javax.swing.text.html.parser.ContentModel;

import kfs.light.core.Starter;

public class NewZoneFileFrame extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1664857059105399658L;

	protected JButton submit;
	protected JTextArea zones;
	public static Boolean finished = false;

	protected ActionListener al = new ActionListener() {

		@Override
		public void actionPerformed(ActionEvent arg0) {
			String newConfig = zones.getText();
			try {
				BufferedWriter bw = new BufferedWriter(new FileWriter(
						Starter.configurationFile));
				bw.write(newConfig);
				bw.close();
				
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
			finished=true;
			
		}
	};

	public NewZoneFileFrame(){
		super("Please define new zones");
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		JPanel content = new JPanel(new GridLayout(0, 1, 0, 0));
		content.add(new JLabel("Application was unable to locate configuration file"));
		content.add(new JLabel("Please provide zone data"));
		content.add(new JLabel("Format: ZoneName x0 y0 x1 y1"));
		zones = new JTextArea(10, 50);	
		JScrollPane texAreaPanel = new JScrollPane(zones);
			
		
		//texAreaPanel.add(zones);
		
		JPanel buttonPanel = new JPanel();
		submit = new JButton("Submit");
		submit.addActionListener(al);
		buttonPanel.add(submit);
		//content.add(submit);
		add(content, BorderLayout.PAGE_START);
		add(texAreaPanel, BorderLayout.CENTER);
		add(buttonPanel, BorderLayout.SOUTH);
		
	}
}
